package com.quanyan.club.web;

import com.quanyan.api.APIResponse;
import com.quanyan.club.entity.vo.resp.RespClubMedal;
import com.quanyan.club.entity.vo.resp.RespClubMedalRule;
import com.quanyan.club.service.ClubMedalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * 俱乐部勋章接口
 * Created by zhang on 16/6/3.
 */
@RestController
@RequestMapping("/api/club/medal")
public class ClubMedalController {

    @Autowired
    private ClubMedalService clubMedalService;

    /**
     * 俱乐部勋章列表
     * @param map
     * @return
     */
    @RequestMapping(value = "list",method = RequestMethod.POST)
    public APIResponse<List<RespClubMedal>> list(@Valid @RequestBody Map map){
        if(null == map.get("clubId")){
            return APIResponse.returnFail("参数为空");
        }
        if(null == map.get("type")){
            return APIResponse.returnFail("参数为空");
        }
        List<RespClubMedal> list;
        try{
            list = clubMedalService.listClubMedal((int)map.get("clubId"),(int)map.get("type"));
        } catch(Exception e){
            e.printStackTrace();
            return APIResponse.returnFail("请输入正整数参数");
        }

        return APIResponse.returnSuccess(list);
    }

    /**
     * 获取勋章规则
     * @param map
     * @return
     */
    @RequestMapping(value = "get",method = RequestMethod.POST)
    public APIResponse<RespClubMedalRule> get(@Valid @RequestBody Map map){
        if(null == map.get("medalId")){
            return APIResponse.returnFail("参数为空");
        }
        RespClubMedalRule clubMedalRule;
        try {
            clubMedalRule = clubMedalService.getMedalRule((int)map.get("medalId"));
        } catch (Exception e) {
            e.printStackTrace();
            return APIResponse.returnFail("请输入正整数参数");
        }
        return APIResponse.returnSuccess(clubMedalRule);
    }
}
